home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Demos / PowerFantasm 4.15 / Beginners guide / Video Library Example / video_demo.s < prev    next >
Encoding:
Text File  |  1996-08-28  |  5.3 KB  |  198 lines

  1. video_demo:
  2.  
  3. **Set up equates for box size
  4. box_top:    equ    100
  5. box_left:    equ    60
  6. box_bottom:    equ    360    box hieght is 260
  7. box_right:    equ    580    box width is 520
  8. **eautes for blob limits
  9. blob_max_left:    equ    box_left
  10. blob_max_right:    equ    box_right-32    **32 is width of icl8
  11. blob_max_top:    equ    box_top
  12. blob_max_bottom:    equ    box_bottom-32
  13.  
  14. outer_border:    equ    34    width of the outer border
  15. border:        equ    15    width of the inner border
  16. purple:        equ    31    colour purple
  17. red:    equ    70
  18. black:        equ    255    colour black
  19.  
  20. blob_id:    equ    128    the blob is icl8 ID 128
  21. ************global variables
  22. blob_pointer:    globoff.l    1    pointer to blob grafic data
  23. blob_handle:    globoff.l    1    handle to blob grafic data
  24. owch_handle:    globoff.l    1    handle of owch sound
  25. eek_handle:    globoff.l    1    handle off eek sound
  26. *********************************************************************************        
  27.         bsr    a5_init            *mandatory
  28.         bsr    init_mac        *mandatory
  29.         bsr    init_graph_lib    *initialise the graphics library
  30.         bsr    hide_mouse    hide the mouse cursor
  31. 
  32.         move.l    #1024,d0        *get 1k for icl8 to live in
  33.         bsr    getmem    
  34.         bsr    lockmem            *lock it
  35.         move.l    a0,blob_handle(a5)    *so we can dispose it when we quit
  36.         move.l    (a0),a0            *get pointer to the memory
  37.         move.l    a0,blob_pointer(a5)
  38. **draw a red box
  39.         move.w    #red,d0
  40.         move.w    #box_left-outer_border,d1
  41.         move.w    #box_right+outer_border,d2
  42.         move.w    #box_top-outer_border,d3
  43.         move.w    #box_bottom+outer_border,d4
  44.         bsr    box_256
  45. **draw a purple box
  46.         move.w    #purple,d0    colour purple
  47.         move.w    #box_left-border,d1    start x
  48.         move.w    #box_right+border,d2    end x
  49.         move.w    #box_top-border,d3    start y
  50.         move.w    #box_bottom+border,d4    end y
  51.         bsr    box_256
  52. **now a black box inside it to make a window
  53.         move.w    #black,d0    colour=black
  54.         move.w    #box_left,d1    start x
  55.         move.w    #box_right,d2    end x
  56.         move.w    #box_top,d3    start y
  57.         move.w    #box_bottom,d4    end y
  58.         bsr    box_256
  59. **print the title
  60.         lea    hello_string(pc),a0    print box title
  61.         move.w    #7,d1    x
  62.         move.w    #7,d2    y
  63.         move.w    #52,d0    colour
  64.         bsr    print_string_8
  65.  
  66. **get owch sound.
  67.  
  68.         move.w    #128,d0
  69.         bsr    get_sound    handle in a0
  70.         move.l    a0,d0
  71.         move.l    d0,owch_handle(a5)
  72.  
  73. **get eek sound
  74.         move.w    #129,d0
  75.         bsr    get_sound
  76.         move.l    a0,d0
  77.         move.l    d0,eek_handle(a5)
  78. **now get the sprite
  79.         MOVE.W    #blob_id,D0    icl8 ID
  80.         move.l    blob_pointer(a5),A1    *get_icl8 needs to know where to put it.
  81.  
  82.         BSR    GET_ICL8    load in the blob icl8 at my_data
  83.         TST.W    D0
  84.         BMI.S    QUIT        couldn't find it!
  85.         
  86.         move.l    blob_pointer(a5),A1    point to blob data
  87. **now set up vectors
  88. blob_x:        requ    d0
  89. blob_y:        requ    d1
  90. vector_x:    requ    d5
  91. vector_y:    requ    d6
  92.     
  93.  
  94.         move.w    #1,`vector_x    x vector - speed=1 pix per frame
  95.         move.w    #1,`vector_y    y vector - speed=1 pix per frame
  96.         
  97.         move.w    #200,`blob_x        initial starting position
  98.         move.w    #200,`blob_y
  99.  
  100. bounce_loop:
  101. ;        movem.l    d0-d2/a1,-(sp)     uncomment these lines to add a 1 tick delay
  102. ;        move.l    #1,d0        wait for two ticks.
  103. ;        bsr    wait
  104. ;        movem.l    (sp)+,d0-d2/a1
  105.         
  106.         bsr    icl8_print    draw the blob
  107.         
  108.         add.w    `vector_x,`blob_x    update position
  109.         add.w    `vector_y,`blob_y
  110.         
  111.         bsr.s    check_boundries        check and adjust vectors if necessary.
  112.         movem.l    d0-d1/a1,-(sp)        *save x,y and pointer to blob
  113.         bsr    plot_a_star        plot a random star
  114.  
  115.         bsr    getkey_turbo        **see manual for keymapping
  116.         tst.w    d0
  117.         bmi.s    quit        *key pressed
  118.  
  119.         movem.l    (sp)+,d0-d1/a1
  120.         bra.s    bounce_loop
  121. QUIT:        movem.l    (sp)+,d0-d1/a1
  122.         bsr    show_mouse    mouse cursor back on
  123.         move.l    blob_handle(a5),a0
  124.         bsr    releasemem
  125.         rts            *end of prog.
  126.         
  127. *********************Misc subroutines**********************
  128. check_boundries:    
  129. **we check blob_x and y and if close to the box boundries we reverse the relevant
  130. **vector.
  131.         cmpi.w    #blob_max_left,`blob_x
  132.         bgt.s    not_min_x    hasn't passed minimum x boundry
  133.         neg.w    `vector_x    reverse the x vector
  134.         bra.s    done_x        check y
  135. not_min_x:    cmpi.w    #blob_max_right,`blob_x
  136.         blt.s    done_x
  137.         neg.w    `vector_x
  138. done_x:        cmpi.w    #blob_max_top,`blob_y
  139.         bgt.s    not_min_y
  140.         neg.w    `vector_y
  141.         
  142.         movem.l    d0-d4,-(sp)    save coords and vectors
  143.         bsr    random
  144.         andi.w    #$f,d0        gt a random number less than 16
  145.         cmpi.w    #2,d0        if its greater than 2 then dont go owch
  146.         bge.s    dont_go_owch
  147.         move.l    owch_handle(a5),a0
  148.         bsr    run_sound    make owch sound
  149. dont_go_owch:
  150.         movem.l    (sp)+,d0-d4    get coords and vectors back
  151.         bra.s    done_y
  152.         
  153. not_min_y:    cmpi.w    #blob_max_bottom,`blob_y
  154.         blt.s    done_y
  155.         neg.w    `vector_y
  156.         movem.l    d0-d4,-(sp)    save coords and vectors
  157.         bsr    random
  158.         andi.w    #$f,d0        gt a random number less than 16
  159.         cmpi.w    #2,d0        if its greater than 2 then dont go eek
  160.         bge.s    dont_go_eek
  161.         move.l    eek_handle(a5),a0
  162.         bsr    run_sound    make owch sound
  163. dont_go_eek:    movem.l    (sp)+,d0-d4    restore coords and vectors
  164.  
  165. done_y:        rts
  166.  
  167. ***********
  168.  
  169. **plot_a_star calls random to get values for a star position and colour.
  170. plot_a_star:    bsr    random        get long random number in d0
  171.         andi.w    #$f,d0        make less than 16
  172.         cmpi.w    #1,d0
  173.         blt.s    do_star        if less than 4 then do a start (1 in 16 chance)
  174.         rts
  175. do_star:
  176.         bsr    random
  177.         andi.l    #$1ff,d0        make in the range of 0-511
  178.         add.w    #box_left,d0
  179.         move.w    d0,d7        save x coord
  180.         bsr    random
  181.         andi.l    #$ff,d0
  182.         add.w    #box_top,d0
  183.         move.w    d0,d2        *y coord
  184.         move.w    d7,d1        *x coord
  185.         bsr    plot_256    *plot it
  186.         rts
  187.         
  188.  
  189. hello_string:    dc.b    "The annoying Blob - An Example for Fantasm V4.00.",0
  190.         even
  191.         global    video_demo
  192.  
  193.         extern    init_mac,a5_init
  194.         extern    init_graph_lib,box_256,getkey_turbo,random
  195.         extern    icl8_print,GET_ICL8,plot_256,wait
  196.         extern    hide_mouse,show_mouse,print_char_8,print_string_8
  197.         extern    getmem,lockmem,releasemem,get_sound,run_sound
  198.